﻿using System.Configuration;
using AT.IBMS.Framework.Configuration;
using AT.IBMS.Framework.Data;
using AT.IBMS.Framework.Logging;
using AT.IBMS.Framework.Tools;

namespace AT.IBMS.Framework
{
    public static class FrameworkManager
    {

        static string frameworkSectionName;

        /// <summary>
        /// 初始化框架。并启动相关服务。
        /// </summary>
        public static void Initialize()
        {

        }

        /// <summary>
        /// 创建框架提供的工具方法。
        /// </summary>
        public static Tool Tool
        {
            get
            {
                return new Tool();
            }
        }

        /// <summary>
        /// 设置框架配置节点的名称。
        /// 默认为“framework”。
        /// </summary>
        public static string FrameworkSectionName
        {
            get
            {

                if (string.IsNullOrWhiteSpace(frameworkSectionName))
                {
                    frameworkSectionName = "framework"; 
                }

                return frameworkSectionName;

            }
            set
            {
                frameworkSectionName = value;
            }
            
        }

        /// <summary>
        /// 获取日志管理器。
        /// </summary>
        public static Logger Logger
        {
            get
            {
                return new Logger();
            }
        }

        /// <summary>
        /// 创建数据访问提供程序。
        /// </summary>
        /// <param name="connectionStringName">数据库连接字符串的名称。</param>
        /// <returns>数据访问提供程序的实例。</returns>
        public static DataProvider CreateDataProvider(string connectionStringName = null)
        {

            string name;

            name = connectionStringName;

            if (string.IsNullOrWhiteSpace(connectionStringName))
            {
                name = FrameworkConfigurationSettings.Data.DefaultConnectionStringName;
            }

            return new DataProvider(name);

        }

        /// <summary>
        /// 框架配置文件节点。
        /// </summary>
        public static FrameworkSection FrameworkConfigurationSettings
        {
            get
            {

                FrameworkSection section;

                section = ConfigurationManager.
                    GetSection(FrameworkSectionName) as FrameworkSection;

                return section;

            }
        }

    }
}
